# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = 'restructuredtext en'
__all__ = []

from ... import formlib as layout
from ... import pilelib as stack
from ...gamelib import info as gi, game
from ...packlib import info as cs
from ...piles import hanafuda as hstack

GT, SL = gi.GT, gi.SL
Wrap = stack.StackWrapper


class FourWindsHn(cs.Hanafuda_Deck, game.Game):
    """
    Finish 1 deck on foundations.

    Layout
      - row [4 (1 cross corner), no offset]
      - talon [N, no offset]
      - waste [1 E talon, no offset]
      - foundation [4 (1 cross arm), no offset]

    :CVariables:
      _talon_ : pysollib.stack.Stack
        .. stack.WasteTalon (max_rounds=2)

        Deal 1 card per `s.waste` on click. 1 redeal.

      _waste_ : pysollib.stack.Stack
        .. stack.WasteStack

        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_Foundation

        Build up in suit by same rank. Play top. Base Pine.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.hanafuda.Suit_RowStack (max_cards=3, max_move=1,
          max_accept=1)

        Build up in suit by same rank. Play top. Max 3 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.defaultHint
    """
    __info__ = dict(id=0x930, name='Four Winds (Hanafuda)',
                    category=cs.TYPE_HANAFUDA, game_type=GT.ONE_DECK, decks=1,
                    redeals=1, skill_level=SL.MOSTLY_SKILL, version='3.20')
    __author__ = 'Markus Oberhumer'
    __version__ = 7.70

    _talon_ = Wrap(stack.WasteTalon, max_rounds=2)
    _waste_ = stack.WasteStack
    _foundation_ = hstack.Suit_Foundation
    _row_ = Wrap(hstack.Suit_RowStack, max_cards=3, max_move=1)

    def _create_game(self, **kw):
        l, s = layout.Layout(self), self.s
        self.table_size = (5 * l.XS + l.XM, 4 * l.YS + 3 * l.YM,)
        x, y = (self.width - 2 * l.XS) / 2, l.YM
        s['talon'] = self._talon_(x, y, game=self)
        l.set_ncards_text(s['talon'], 'sw')
        l.set_rounds_text(self.s['talon'], 'nw')
        x += l.XS
        s['wastes'].append(self._waste_(x, y, game=self))
        l.set_ncards_text(s['wastes'][-1], 'se')
        for (dx, dy), suit, text in zip(((2, 0), (1, 1), (2, 1), (3, 1),
                                         (2, 2),), l.RANK, (_('North'),
                                          _('East'), _('South'), _('West'),)):
            x, y = l.delta_coords(y=l.YM + l.YS, dx=dx, dy=dy)
            s['foundations'].append(self._foundation_(x, y, game=self,
                                                   suit=suit))
            l.set_misc_text(s['foundations'][-1], anchor='s', text=text)
        for (dx, dy), text in zip(((0, 0,), (3, 0,) (0, 3,), (3, 3),),
                                    (_('NW'), _('NE'), _('SE'), _('SW'),)):
            x, y = l.delta_coords(y=l.YM + l.YS, dx=dx, dy=dy)
            s['rows'].append(self._row_(x, y, game=self, offset=(0, 0)))
            l.set_misc_text(s['rows'][-1], anchor='s', text=text)
        l.defaultStackGroups()
        return l

    def _start(self, **kw):
        """
        Deal initial cards for new game.

        .. \_start([]) -> None
        """
        pass


PROVIDES = [FourWindsHn]